// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
//import './common/common'
//import { Http, Storage } from 'ipn'
import Vue from 'vue'
import App from './App'
import router from './router'
//import wx from 'weixin-js-sdk';
global.WECHAT_APP_ID = process.env.WECHAT_APP_ID;
global.wechatAuthorize = function () {
	var href = 'http://' + window.location.host + '/?t=2017/#/wechatLogin';
  let currentUrl = encodeURIComponent(href);
  let redirectUrl = encodeURIComponent(global.API_BASE_PATH + '/weixin/redirect?paramtype=hash&uri=' + currentUrl);
  window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + global.WECHAT_APP_ID + '&redirect_uri=' + redirectUrl + '&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect';
};
//发射小程序分享链接
//global.referer = function(img, title) {
//	//商品详情分享
//	if(router.currentRoute.fullPath.indexOf('goods/detail') != -1){
//		var xcxUrl = '/pages/index/index?path=' + encodeURIComponent(router.currentRoute.fullPath);
//	} else {
//		var xcxUrl = '/pages/index/index';
//	}
//	wx.miniProgram.postMessage({data:{url: xcxUrl,imgUrl: img, title: title}})
//}
// 登录
global.login = function () {
	//app登录
	if (navigator.userAgent.indexOf('Platform/') !=-1) {
		WebAppJS.nativeRouterPage('/passport/login/temp')
		return
	}
	var referer = router.currentRoute.fullPath;
	var path = router.currentRoute.path;
	//小程序登录
//if(sessionStorage.getItem('wxType') != null){
//	var redirect = 'pages/index/index' + encodeURIComponent('?path=' + referer);
//	var path = '/pages/login/index?redirect=' + redirect;
//		wx.miniProgram.redirectTo({url: path});
//		return
//	}
  //H5登录
  if(path && path != '' && path != null && path !=undefined && path != '/login' && path != '/wechatLogin' && path != '/centerLogin'){
	  Storage.set('referer', referer)
  }
  global.wechatAuthorize();
//router.replace('/wechatLogin')
}

// 获取上传token
global.getUploadUrl = function () {
  return global.API_BASE_PATH + '/upload/image'
}

//// 错误提示
//global.showError = function (message) {
//Vue.$vux.toast.show({text: message, type: 'text', 'width': '10rem'})
//}
//
//// 成功提示
//global.showSuccess = function (message) {
//Vue.$vux.toast.show({text: message, type: 'success', width: '10rem'})
//}
//global.toast = function (message) {
//Vue.$vux.toast.show({text: message, type: 'text', width: '10rem', position: 'center'})
//}

//FastClick.attach(document.body)

Vue.config.productionTip = false
//Vue.prototype.$http = Http
//Vue.prototype.ajax = Http.execute
//Vue.prototype.toast = global.toast
//Vue.prototype.showError = global.showError
//Vue.prototype.showSuccess = global.showSuccess
//Vue.prototype.loading = Vue.$vux.loading
Vue.prototype.setDocumentTitle = global.setDocumentTitle

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  template: '<App/>',
  components: { App }
});
